package com.bdhub.handld;

import com.bdhub.im.server.protobuf.MessageProtobuf;
import com.bdhub.interfaces.EventListener;
import com.bdhub.tools.MessageConvert;

/**
 * 消息转发器，将消息转发到应用层
 * @author lp
 *
 */
public class MsgDispatcher  {
	private EventListener listener = null;
	private ClientBootstrap clientBootstrap;
	public MsgDispatcher(ClientBootstrap clientBootstrap) {
		this.clientBootstrap =clientBootstrap;
	}

	public void setListener(EventListener listener) {
		this.listener = listener;
	}
	/**
	 * 接收消息
	 * 
	 * @param message
	 */
	public void receiveMsg(MessageProtobuf.CMsg message) {
		if(message.getHead().getType() == 1003){
			return;
		}
		//消息解码
		message = MessageConvert.messageDecoding(message);
		listener.handleEvent(message);
		clientBootstrap.processMsg(message);
	}

}
